<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>TodoList</title>
    <script src="../../assets/vue.js"></script>
</head>
<body>
    <div id="root">
       <div>Parent: {{msg}}</div>
       <child :msg="msg" v-on:change="changeMsg"></child>
    </div>
    <script>
        var child = {
            template: '<div><div>child: {{msg}}</div>' + 
                    '<button v-on:click="handleClick">改变parent的msg</button></div>',
            props: {
                msg: String
            },
            methods: {
                handleClick: function(){
                    this.$emit('change', 'child msg')
                }
            }
        }
        new Vue({   
            el: '#root',
            components: {
                child
            },
            data: {
                msg: 'Hello'
            },
            methods: {
                changeMsg: function(msg) {
                    this.msg = msg
                }
            }
        })
    </script>
</body>
</html>